import os
from datetime import datetime

def tree(directory, indent=''):
    files = os.listdir(directory)
    for file_name in files:
        path = os.path.join(directory, file_name)
        if os.path.isdir(path):
            print(indent + '|-- ' + file_name)
            tree(path, indent + '|   ')
        else:
            print(indent + '|-- ' + file_name)

try:
    # 输入要查询的路径
    path = input("请输入要查询的路径，按回车键确认：")
    # 检查路径是否存在
    if not os.path.exists(path):
        raise FileNotFoundError("系统找不到指定的路径: " + path)
    # 调用tree函数
    tree(path)
    print("目录结构生成成功！")
except KeyboardInterrupt:
    print("输入错误！")
except FileNotFoundError as e:
    print(str(e))
except OSError:
    print("文件名、目录名或卷标语法不正确。")

input("按任意键退出...")
